﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ThanhTu.GNC.Media.KQXS.DataAccess.DAL;
using ThanhTu.GNC.Media.KQXS.DataAccess.DO;
using System.Data;
using System.Text.RegularExpressions;

namespace GNCMedia.KQXS.Admin
{
    public class RequimenData
    {
        public bool checkdata(string idtinh, string idvung, string tentinh)
        {
            if (idtinh.Trim().Equals("") || tentinh.Trim().Equals("")||idvung.Equals(""))
            {
                return false;
            }
            return true;
        }
        public bool CheckIDprovince(string provinceID,string provinceName)
        {
            ProvinceDAL province = new ProvinceDAL();
            List<ProvinceDO> allData = province.selectadd();
            foreach (ProvinceDO item in allData)
            {
                if (provinceID.Equals(item.ProvinceID.ToString())|| provinceName.Equals(item.PrinceName.ToUpper().ToString()))
                {
                    return false;
                }
            }
            return true;
        }
        public bool CheckduplicateProvince(string newOpendate, string AddProvinceID)
        {
            TimeofAwardsDAL addNewAwards = new TimeofAwardsDAL();
            int rowcount = 0;
           
            foreach (DataRow item in addNewAwards.SelectALL_QT(1,5,ref rowcount).Rows)
            {
               // string thu = item.DateOfAwards.ToString();
                //string id = item.ProvinceID.ToString();
                if (newOpendate.Equals(item["DATEAWARDS_ID"].ToString()) && AddProvinceID.Equals(item["PROVINCEID"].ToString()))
                {
                    return false;
                }
            }
            return true;
        }

        public bool checkData(string settingName, string settingType, string position, string settingValue)
        {
            if (settingName.Trim().Equals("") || settingType.Trim().Equals("") || position.Trim().Equals("") || settingValue.Trim().Equals(""))
            {
                return false;
            }
            return true;
        }

        public bool checkRangeNumber5digit(string number)
        {
            if (number.Length < 5)
            {
                return false;
            }

            return true;
        }
        public bool checkRangeNumber4digit(string number)
        {
            if (number.Length < 4)
            {
                return false;
            }
            return true;
        }
        public bool checkRangeNumber3digit(string number)
        {

            if (number.Length < 3)
            {
                return false;
            }
            return true;
        }
        public bool checkRangeNumber2digit(string number)
        {
            if (number.Length < 2)
            {
                return false;
            }
            return true;
        }

        public bool CheckResultsIDprovince(string provinceID)
        {
            ResultLotteryDAL resultprovince = new ResultLotteryDAL();
            int rowncount = 0;

            foreach (DataRow item in resultprovince.SelectAll_KQ_User(1, 10, ref rowncount).Rows)
            {
                if (item["PROVINCE_ID"].Equals(provinceID))
                {
                    return false;
                }
            }
            return true;
        }

        public bool CheckResultByIdProvinceAndDate(string provinceID, DateTime resultDate)
        {
            ResultLotteryDAL resultprovince = new ResultLotteryDAL();
            int rowncount = 0;

            foreach (DataRow item in resultprovince.SelectAll_KQ_User(1, 10, ref rowncount).Rows)
            {
                DateTime checkDate = Convert.ToDateTime(item["RESULTDATE"].ToString());
                if (item["PROVINCE_ID"].ToString().Equals(provinceID) && checkDate.Equals(resultDate))
                {
                    return false;
                }
            }
            return true;
        }

        public bool checkDataResult(string variable1, string variable2, string variable3, string variable4, string variable5, string variable6)
        {
            if (!Regex.IsMatch(variable1, "^-?\\d*(d+)?$")
                && !Regex.IsMatch(variable1, "^-?\\d*(d+)?$")
                && !Regex.IsMatch(variable2, "^-?\\d*(d+)?$")
                && !Regex.IsMatch(variable3, "^-?\\d*(d+)?$")
                && !Regex.IsMatch(variable4, "^-?\\d*(d+)?$")
                && !Regex.IsMatch(variable6, "^-?\\d*(d+)?$")
                 && !Regex.IsMatch(variable6, "^-?\\d*(d+)?$"))
            {
                return false;
            }
            return true;
        }
        public bool checkInfoComment(string email, string phone, string content)
        {
            if (email.Trim().Equals("") || phone.Trim().Equals("") || content.Trim().Equals("") || phone.Length < 10 || phone.Length > 11)
            {
                return false;

            }
            return true;
        }


        public bool CheckNullData_XSMB(string ngaymo, string giaidb, string giainhat, string giainhi1, string giainhi2,
       string giaiba1, string giaiba2, string giaiba3, string giaiba4, string giaiba5, string giaiba6,
           string giaitu1, string giaitu2, string giaitu3, string giaitu4,
               string giainam1, string giainam2, string giainam3, string giainam4, string giainam5, string giainam6,
                  string giaisau1, string giaisau2, string giaisau3,
                      string giaibay1, string giaibay2, string giaibay3, string giaibay4)
        {
            if (ngaymo.Equals("") || giaidb.Equals("") || giainhat.Equals("") ||
                 giainhi1.Equals("") || giainhi2.Equals("") ||
                giaiba1.Equals("") || giaiba2.Equals("") || giaiba3.Equals("") || giaiba4.Equals("") || giaiba5.Equals("") || giaiba6.Equals("") ||
                  giaitu1.Equals("") || giaitu2.Equals("") || giaitu3.Equals("") || giaitu4.Equals("") ||
                       giainam1.Equals("") || giainam2.Equals("") || giainam3.Equals("") || giainam4.Equals("") || giainam5.Equals("") || giainam6.Equals("") ||
                              giaisau1.Equals("") || giaisau2.Equals("") || giaisau3.Equals("") ||
                                    giaibay1.Equals("") || giaibay2.Equals("") || giaibay3.Equals("") || giaibay4.Equals(""))
            {
                return false;
            }

            return true;
        }


        public bool CheckNullData_otherProvince(string ngaymo, string giaidb, string giainhat, string giainhi1,
         string giaiba1, string giaiba2,
             string giaitu1, string giaitu2, string giaitu3, string giaitu4, string giaitu5, string giaitu6, string giaitu7,
                 string giainam1,
                    string giaisau1, string giaisau2, string giaisau3,
                        string giaibay1, string giaiTam)
        {
            if (ngaymo.Equals("") || giaidb.Equals("")
                || giainhat.Equals("") ||
                 giainhi1.Equals("") ||
                giaiba1.Equals("") || giaiba2.Equals("") ||
                  giaitu1.Equals("") || giaitu2.Equals("") || giaitu3.Equals("") || giaitu4.Equals("") || giaitu5.Equals("") || giaitu6.Equals("") || giaitu7.Equals("") ||
                       giainam1.Equals("") ||
                              giaisau1.Equals("") || giaisau2.Equals("") || giaisau3.Equals("") ||
                                    giaibay1.Equals("")
                                    || giaiTam.Equals(""))
            {
                return false;
            }

            return true;
        }

        public bool Check_Math_Data_XSMB(string ngaymo, string giaidb, string giainhat, string giainhi1, string giainhi2,
         string giaiba1, string giaiba2, string giaiba3, string giaiba4, string giaiba5, string giaiba6,
             string giaitu1, string giaitu2, string giaitu3, string giaitu4,
                 string giainam1, string giainam2, string giainam3, string giainam4, string giainam5, string giainam6,
                    string giaisau1, string giaisau2, string giaisau3,
                        string giaibay1, string giaibay2, string giaibay3, string giaibay4)
        {

            if (!Regex.IsMatch(ngaymo, "^((((0[13578])|([13578])|(1[02]))[\\/](([1-9])|([0-2][0-9])|(3[01])))|(((0[469])|([469])|(11))[\\/](([1-9])|([0-2][0-9])|(30)))|((2|02)[\\/](([1-9])|([0-2][0-9]))))[\\/]\\d{4}$|^\\d{4}$") ||
                        !Regex.IsMatch(giaidb, "^-?\\d*(d+)?$") ||
                            !Regex.IsMatch(giainhat, "^-?\\d*(d+)?$") ||
                            !Regex.IsMatch(giainhi1, "^-?\\d*(d+)?$") ||
                            !Regex.IsMatch(giainhi2, "^-?\\d*(d+)?$") ||
                            !checkDataResult(giaiba1, giaiba2, giaiba3, giaiba4, giaiba5, giaiba6) ||
                            !Regex.IsMatch(giaitu1, "^-?\\d*(d+)?$") ||
                        !Regex.IsMatch(giaitu2, "^-?\\d*(d+)?$") ||
                         !Regex.IsMatch(giaitu3, "^-?\\d*(d+)?$") ||
                        !Regex.IsMatch(giaitu4, "^-?\\d*(d+)?$") ||
                    !checkDataResult(giainam1, giainam2, giainam3, giainam4, giainam5, giainam6) ||
                    !Regex.IsMatch(giaisau1, "^-?\\d*(d+)?$") ||
                     !Regex.IsMatch(giaisau2, "^-?\\d*(d+)?$") ||
                      !Regex.IsMatch(giaisau3, "^-?\\d*(d+)?$") ||
                      !Regex.IsMatch(giaibay1, "^-?\\d*(d+)?$") ||
                        !Regex.IsMatch(giaibay2, "^-?\\d*(d+)?$") ||
                        !Regex.IsMatch(giaibay3, "^-?\\d*(d+)?$") ||
                        !Regex.IsMatch(giaibay4, "^-?\\d*(d+)?$"))
            {
                return false;
            }

            return true;
        }

        public bool Check_Math_Data_XSMB_UPDATE(string giaidb, string giainhat, string giainhi1, string giainhi2,
 string giaiba1, string giaiba2, string giaiba3, string giaiba4, string giaiba5, string giaiba6,
     string giaitu1, string giaitu2, string giaitu3, string giaitu4,
         string giainam1, string giainam2, string giainam3, string giainam4, string giainam5, string giainam6,
            string giaisau1, string giaisau2, string giaisau3,
                string giaibay1, string giaibay2, string giaibay3, string giaibay4)
        {

            if (
                        !Regex.IsMatch(giaidb, "^-?\\d*(d+)?$") ||
                            !Regex.IsMatch(giainhat, "^-?\\d*(d+)?$") ||
                            !Regex.IsMatch(giainhi1, "^-?\\d*(d+)?$") ||
                            !Regex.IsMatch(giainhi2, "^-?\\d*(d+)?$") ||
                            !checkDataResult(giaiba1, giaiba2, giaiba3, giaiba4, giaiba5, giaiba6) ||
                            !Regex.IsMatch(giaitu1, "^-?\\d*(d+)?$") ||
                        !Regex.IsMatch(giaitu2, "^-?\\d*(d+)?$") ||
                         !Regex.IsMatch(giaitu3, "^-?\\d*(d+)?$") ||
                        !Regex.IsMatch(giaitu4, "^-?\\d*(d+)?$") ||
                    !checkDataResult(giainam1, giainam2, giainam3, giainam4, giainam5, giainam6) ||
                    !Regex.IsMatch(giaisau1, "^-?\\d*(d+)?$") ||
                     !Regex.IsMatch(giaisau2, "^-?\\d*(d+)?$") ||
                      !Regex.IsMatch(giaisau3, "^-?\\d*(d+)?$") ||
                      !Regex.IsMatch(giaibay1, "^-?\\d*(d+)?$") ||
                        !Regex.IsMatch(giaibay2, "^-?\\d*(d+)?$") ||
                        !Regex.IsMatch(giaibay3, "^-?\\d*(d+)?$") ||
                        !Regex.IsMatch(giaibay4, "^-?\\d*(d+)?$"))
            {
                return false;
            }

            return true;
        }
        public bool Check_Math_Data_OtherProvince(string ngaymo, string giaidb, string giainhat, string giainhi1,
         string giaiba1, string giaiba2,
             string giaitu1, string giaitu2, string giaitu3, string giaitu4, string giaitu5, string giaitu6, string giaitu7,
                 string giainam1,
                    string giaisau1, string giaisau2, string giaisau3,
                        string giaibay1, string giaiTam)
        {



            if (!Regex.IsMatch(ngaymo, "^((((0[13578])|([13578])|(1[02]))[\\/](([1-9])|([0-2][0-9])|(3[01])))|(((0[469])|([469])|(11))[\\/](([1-9])|([0-2][0-9])|(30)))|((2|02)[\\/](([1-9])|([0-2][0-9]))))[\\/]\\d{4}$|^\\d{4}$") ||
                        !Regex.IsMatch(giaidb, "^-?\\d*(d+)?$") ||
                            !Regex.IsMatch(giainhat, "^-?\\d*(d+)?$") ||
                            !Regex.IsMatch(giainhi1, "^-?\\d*(d+)?$") ||
                             !Regex.IsMatch(giaiba1, "^-?\\d*(d+)?$") ||
                             !Regex.IsMatch(giaiba2, "^-?\\d*(d+)?$") ||
                            !Regex.IsMatch(giaitu1, "^-?\\d*(d+)?$") ||
                        !Regex.IsMatch(giaitu2, "^-?\\d*(d+)?$") ||
                         !Regex.IsMatch(giaitu3, "^-?\\d*(d+)?$") ||
                        !Regex.IsMatch(giaitu4, "^-?\\d*(d+)?$") ||
                         !Regex.IsMatch(giaitu5, "^-?\\d*(d+)?$") ||
                         !Regex.IsMatch(giaitu6, "^-?\\d*(d+)?$") ||
                        !Regex.IsMatch(giaitu7, "^-?\\d*(d+)?$") ||
                   !Regex.IsMatch(giainam1, "^-?\\d*(d+)?$") ||
                    !Regex.IsMatch(giaisau1, "^-?\\d*(d+)?$") ||
                     !Regex.IsMatch(giaisau2, "^-?\\d*(d+)?$") ||
                      !Regex.IsMatch(giaisau3, "^-?\\d*(d+)?$") ||
                      !Regex.IsMatch(giaibay1, "^-?\\d*(d+)?$") ||
                        !Regex.IsMatch(giaiTam, "^-?\\d*(d+)?$"))
            {
                return false;
            }

            return true;
        }


        public bool Check_Math_Data_OtherProvince_UPDATE(string giaidb, string giainhat, string giainhi1,
        string giaiba1, string giaiba2,
            string giaitu1, string giaitu2, string giaitu3, string giaitu4, string giaitu5, string giaitu6, string giaitu7,
                string giainam1,
                   string giaisau1, string giaisau2, string giaisau3,
                       string giaibay1, string giaiTam)
        {



            if (
                        !Regex.IsMatch(giaidb, "^-?\\d*(d+)?$") ||
                            !Regex.IsMatch(giainhat, "^-?\\d*(d+)?$") ||
                            !Regex.IsMatch(giainhi1, "^-?\\d*(d+)?$") ||
                             !Regex.IsMatch(giaiba1, "^-?\\d*(d+)?$") ||
                             !Regex.IsMatch(giaiba2, "^-?\\d*(d+)?$") ||
                            !Regex.IsMatch(giaitu1, "^-?\\d*(d+)?$") ||
                        !Regex.IsMatch(giaitu2, "^-?\\d*(d+)?$") ||
                         !Regex.IsMatch(giaitu3, "^-?\\d*(d+)?$") ||
                        !Regex.IsMatch(giaitu4, "^-?\\d*(d+)?$") ||
                         !Regex.IsMatch(giaitu5, "^-?\\d*(d+)?$") ||
                         !Regex.IsMatch(giaitu6, "^-?\\d*(d+)?$") ||
                        !Regex.IsMatch(giaitu7, "^-?\\d*(d+)?$") ||
                   !Regex.IsMatch(giainam1, "^-?\\d*(d+)?$") ||
                    !Regex.IsMatch(giaisau1, "^-?\\d*(d+)?$") ||
                     !Regex.IsMatch(giaisau2, "^-?\\d*(d+)?$") ||
                      !Regex.IsMatch(giaisau3, "^-?\\d*(d+)?$") ||
                      !Regex.IsMatch(giaibay1, "^-?\\d*(d+)?$") ||
                        !Regex.IsMatch(giaiTam, "^-?\\d*(d+)?$"))
            {
                return false;
            }

            return true;
        }
    }
}